//
//  LBTipsView.m
//  app
//
//  Created by LINAICAI on 16/6/1.
//  Copyright © 2016年 广东联结电子商务有限公司. All rights reserved.
//

#import "LBTipsView.h"
@interface LBTipsView()
//关闭按钮
@property(nonatomic , strong)UIButton *closeButton;
//中心的图片
@property(nonatomic , strong)UIImageView *tipsImageView;
//标题
@property(nonatomic , strong)UILabel *titleLabel;
//提示正文
@property(nonatomic , strong)UILabel *contentLabel;
//中间的容器视图
@property(nonatomic , strong)UIView *contentView;
@end
@implementation LBTipsView

+ (instancetype)shared
{
    static __kindof LBTipsView *sharedInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedInstance = [[self alloc] initWithFrame:[UIScreen mainScreen].bounds];
        sharedInstance.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
    });
    return sharedInstance;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}
-(void)initialize{
    self.contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 264, 370)];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 3.0f;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.center = self.center;
    [self addSubview:self.contentView];
    
    self.tipsImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"LBTipsView.bundle/lb_tips_icon"]];
    [self.tipsImageView setFrame:CGRectMake(self.contentView.bounds.size.width/2-152/2, self.contentView.bounds.size.height/2-152/2, 152, 152)];
    [self.contentView addSubview:self.tipsImageView];
    
    self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.closeButton setImage:[UIImage imageNamed:@"LBTipsView.bundle/lb_tips_close"] forState:UIControlStateNormal];
    [self.closeButton setFrame:CGRectMake(self.contentView.bounds.size.width-18-8, 8, 18, 18)];
    [self.closeButton addTarget:self action:@selector(hidTips) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.closeButton];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 44, self.contentView.bounds.size.width, 60)];
    [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
    self.titleLabel.text = @"敬请期待";
    self.titleLabel.font = [UIFont boldSystemFontOfSize:36];
    
    self.titleLabel.textColor = [UIColor colorWithRed:214/255.0 green:214/255.0 blue:214/255.0 alpha:1];
    [self.contentView addSubview:self.titleLabel];
    
    self.contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.tipsImageView.frame.origin.y+self.tipsImageView.frame.size.height+20, self.contentView.bounds.size.width, 60)];
    [self.contentLabel setTextAlignment:NSTextAlignmentCenter];
    self.contentLabel.text = @"栏目建设中";
    self.contentLabel.font = [UIFont systemFontOfSize:20];
    self.contentLabel.textColor = [UIColor colorWithRed:214/255.0 green:214/255.0 blue:214/255.0 alpha:1];
    [self.contentView addSubview:self.contentLabel];
    
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hidTips)]];
    
}
- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    
}
- (void)showTips{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    self.alpha = 0.f;
    self.contentView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.8, 0.8);
    [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{
        self.alpha = 1;
        self.contentView.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        
    }];
}
- (void)hidTips{
    if ([[UIApplication sharedApplication].keyWindow.subviews containsObject:self]) {
        [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:5 options:UIViewAnimationOptionCurveLinear animations:^{
            self.alpha = 0;
            
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];

    }
}
@end
